﻿using BLL;
using System;
using System.Collections.Generic;
using System.Data;

namespace Thksoft.Module.StatisticalReport
{
    public partial class WeekDataReport : BaseUI.BasePage
    {
        private QS_PLANWEEKAPPLYBLL planWeekApplyBLL = new QS_PLANWEEKAPPLYBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BinData();
            }
        }

        public void BinData()
        {
            var id = Request.QueryString["ID"];
            if (string.IsNullOrEmpty(id))
            {
                MessageBox.Show(this, "参数传入错误");
                return;
            }
            BinDataByWeekTable(Convert.ToDecimal(id));
        }

        #region 周资金详情

        public void BinDataByWeekTable(decimal id)
        {
            var entity = planWeekApplyBLL.Find(id);
            if (entity == null)
            {
                MessageBox.Show(this, "周资金信息未找到");
                return;
            }
            var sql = @"SELECT T1.*,T2.*,T3.C_NAME AS BANK_NAME FROM QS_PLANWEEK_DETAIL T1
INNER JOIN YX_BANK_DETAILLIST T2
ON T1.C_PROWEEKNUM = T2.C_PROWEEKNUM
LEFT JOIN SYS_BANK T3
ON T2.N_BANK_ID = T3.N_ID
WHERE T1.N_WEEKAPP_ID = {0}";
            sql = string.Format(sql, entity.N_WEEKAPP_ID);
            var dt = planWeekApplyBLL.Query(sql);
            var data = new List<WEEK_TABLE_MODEL>();
            foreach (DataRow row in dt.Rows)
            {
                var itemData = new WEEK_TABLE_MODEL();
                itemData.ID = Convert.ToInt32(row["N_DETAIL_LISTID"]);
                itemData.REMARK = Convert.ToString(row["C_DET"]);
                itemData.ACCOUNT_FLOW = Convert.ToString(row["C_TRAN_FLOW"]);
                itemData.ACCOUNT = Convert.ToString(row["C_ACCNO2"]);
                itemData.ACCOUNT_NAME = Convert.ToString(row["C_ACC_NAME1"]);
                itemData.MONEY = Convert.ToDecimal(row["N_AMT"]);
                itemData.SCOP_DATE = Convert.ToDateTime(row["D_TRANDATE"]);
                itemData.BANK_ID = Convert.ToInt32(row["N_BANK_ID"]);
                itemData.BANK_NAME = Convert.ToString(row["BANK_NAME"]);
                itemData.FLAG = Convert.ToInt32(row["N_FLAG1"]) == 1 ? true : false;
                data.Add(itemData);
            }

            WEEK_TABLE.DataSource = data;
            WEEK_TABLE.DataBind();
        }

        #endregion 周资金详情
    }
}